import env from '../env'
import store from '@/store'
import request from './request'

/**
 * 文件图片上传
 * @param {Object} params - 参数 file url
 */
export const uploadFile = async (url, uploadUrl = `system/oss/upload`) => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: `${env.baseURL}/${uploadUrl}`,
			filePath: url,
			name: 'file',
			header: {
				Authorization: `Bearer ${store.state.userInfo.token}`
			},
			success: res => {
				let data
				if (typeof res.data === 'string') {
					data = JSON.parse(res.data)
				}
				setTimeout(() => {
					resolve(data.data)
				}, 1000)
			}
		})
	})
}

// 根据图片ossId删除图片
export const removeByOssId = params => {
  return request.delete(`system/oss/${params}`)
}